home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Advanced V211776152001.psc / frmColorPicker.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-06-14  |  35.9 KB  |  1,049 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmColorPicker 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   " Color picker"
  6.    ClientHeight    =   4440
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   9045
  10.    ClipControls    =   0   'False
  11.    Icon            =   "frmColorPicker.frx":0000
  12.    KeyPreview      =   -1  'True
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   4440
  16.    ScaleWidth      =   9045
  17.    Begin MSComDlg.CommonDialog CDL 
  18.       Left            =   2700
  19.       Top             =   180
  20.       _ExtentX        =   847
  21.       _ExtentY        =   847
  22.       _Version        =   393216
  23.       CancelError     =   -1  'True
  24.    End
  25.    Begin VB.OptionButton opPal 
  26.       Caption         =   "IExplorer 4+"
  27.       Height          =   195
  28.       Index           =   2
  29.       Left            =   7020
  30.       TabIndex        =   45
  31.       Top             =   4185
  32.       Width           =   1185
  33.    End
  34.    Begin VB.OptionButton opPal 
  35.       Caption         =   "PC / MAC"
  36.       Height          =   195
  37.       Index           =   1
  38.       Left            =   5850
  39.       TabIndex        =   44
  40.       Top             =   4185
  41.       Width           =   1095
  42.    End
  43.    Begin VB.OptionButton opPal 
  44.       Caption         =   "Gradient"
  45.       Height          =   195
  46.       Index           =   0
  47.       Left            =   4680
  48.       TabIndex        =   43
  49.       Top             =   4185
  50.       Value           =   -1  'True
  51.       Width           =   1050
  52.    End
  53.    Begin VB.Frame Frame2 
  54.       Height          =   2355
  55.       Left            =   45
  56.       TabIndex        =   33
  57.       Top             =   1215
  58.       Width           =   2220
  59.       Begin VB.ComboBox cbWeb 
  60.          Height          =   315
  61.          Left            =   585
  62.          Style           =   2  'Dropdown List
  63.          TabIndex        =   8
  64.          ToolTipText     =   "Lists the colors supported by Internet Explorer 4+"
  65.          Top             =   1440
  66.          Width           =   1545
  67.       End
  68.       Begin VB.TextBox txCol 
  69.          Height          =   330
  70.          Index           =   0
  71.          Left            =   585
  72.          TabIndex        =   2
  73.          Text            =   "0"
  74.          Top             =   225
  75.          Width           =   1095
  76.       End
  77.       Begin VB.TextBox txCol 
  78.          Height          =   330
  79.          Index           =   1
  80.          Left            =   570
  81.          TabIndex        =   4
  82.          Text            =   "0"
  83.          Top             =   630
  84.          Width           =   1095
  85.       End
  86.       Begin VB.CommandButton btCopy 
  87.          Caption         =   "&1"
  88.          Height          =   330
  89.          Index           =   0
  90.          Left            =   1695
  91.          TabIndex        =   36
  92.          ToolTipText     =   "Copy to clipboard"
  93.          Top             =   225
  94.          Width           =   420
  95.       End
  96.       Begin VB.CommandButton btCopy 
  97.          Caption         =   "&2"
  98.          Height          =   330
  99.          Index           =   1
  100.          Left            =   1695
  101.          TabIndex        =   35
  102.          ToolTipText     =   "Copy to clipboard"
  103.          Top             =   630
  104.          Width           =   420
  105.       End
  106.       Begin VB.TextBox txCol 
  107.          Height          =   330
  108.          Index           =   2
  109.          Left            =   585
  110.          TabIndex        =   6
  111.          Text            =   "0"
  112.          Top             =   1035
  113.          Width           =   1095
  114.       End
  115.       Begin VB.CommandButton btCopy 
  116.          Caption         =   "&3"
  117.          Height          =   330
  118.          Index           =   2
  119.          Left            =   1695
  120.          TabIndex        =   34
  121.          ToolTipText     =   "Copy to clipboard"
  122.          Top             =   1035
  123.          Width           =   420
  124.       End
  125.       Begin VB.Label Label2 
  126.          Caption         =   "&IE 4+"
  127.          Height          =   195
  128.          Left            =   90
  129.          TabIndex        =   7
  130.          Top             =   1485
  131.          Width           =   420
  132.       End
  133.       Begin VB.Label lbCol 
  134.          Caption         =   "&Long:"
  135.          Height          =   285
  136.          Index           =   0
  137.          Left            =   90
  138.          TabIndex        =   1
  139.          Top             =   270
  140.          Width           =   600
  141.       End
  142.       Begin VB.Label lbCol 
  143.          Caption         =   "&Hex:"
  144.          Height          =   285
  145.          Index           =   1
  146.          Left            =   90
  147.          TabIndex        =   3
  148.          Top             =   675
  149.          Width           =   600
  150.       End
  151.       Begin VB.Label lbCol 
  152.          Caption         =   "&RGB:"
  153.          Height          =   330
  154.          Index           =   2
  155.          Left            =   90
  156.          TabIndex        =   5
  157.          Top             =   1080
  158.          Width           =   645
  159.       End
  160.    End
  161.    Begin VB.Frame Frame1 
  162.       Height          =   2355
  163.       Left            =   2340
  164.       TabIndex        =   26
  165.       Top             =   1215
  166.       Width           =   2220
  167.       Begin VB.OptionButton opModify 
  168.          Caption         =   "Web safe color"
  169.          Height          =   240
  170.          Index           =   2
  171.          Left            =   90
  172.          TabIndex        =   48
  173.          Top             =   2070
  174.          Width           =   1995
  175.       End
  176.       Begin VB.OptionButton opModify 
  177.          Caption         =   "16-bit color"
  178.          Height          =   240
  179.          Index           =   1
  180.          Left            =   90
  181.          TabIndex        =   47
  182.          Top             =   1845
  183.          Width           =   1995
  184.       End
  185.       Begin VB.OptionButton opModify 
  186.          Caption         =   "24-bit color"
  187.          Height          =   240
  188.          Index           =   0
  189.          Left            =   90
  190.          TabIndex        =   46
  191.          Top             =   1620
  192.          Value           =   -1  'True
  193.          Width           =   1995
  194.       End
  195.       Begin VB.HScrollBar scColor 
  196.          Height          =   240
  197.          Index           =   0
  198.          LargeChange     =   16
  199.          Left            =   630
  200.          Max             =   255
  201.          TabIndex        =   29
  202.          Top             =   315
  203.          Width           =   1500
  204.       End
  205.       Begin VB.HScrollBar scColor 
  206.          Height          =   240
  207.          Index           =   1
  208.          LargeChange     =   16
  209.          Left            =   630
  210.          Max             =   255
  211.          TabIndex        =   28
  212.          Top             =   765
  213.          Width           =   1500
  214.       End
  215.       Begin VB.HScrollBar scColor 
  216.          Height          =   240
  217.          Index           =   2
  218.          LargeChange     =   16
  219.          Left            =   630
  220.          Max             =   255
  221.          TabIndex        =   27
  222.          Top             =   1215
  223.          Width           =   1500
  224.       End
  225.       Begin VB.Label lbRGB 
  226.          Alignment       =   2  'Center
  227.          BackColor       =   &H000000FF&
  228.          Caption         =   "R"
  229.          BeginProperty Font 
  230.             Name            =   "MS Sans Serif"
  231.             Size            =   8.25
  232.             Charset         =   204
  233.             Weight          =   700
  234.             Underline       =   0   'False
  235.             Italic          =   0   'False
  236.             Strikethrough   =   0   'False
  237.          EndProperty
  238.          ForeColor       =   &H00FFFFFF&
  239.          Height          =   240
  240.          Index           =   0
  241.          Left            =   90
  242.          TabIndex        =   32
  243.          Top             =   315
  244.          Width           =   510
  245.       End
  246.       Begin VB.Label lbRGB 
  247.          Alignment       =   2  'Center
  248.          BackColor       =   &H0000FF00&
  249.          Caption         =   "G"
  250.          BeginProperty Font 
  251.             Name            =   "MS Sans Serif"
  252.             Size            =   8.25
  253.             Charset         =   204
  254.             Weight          =   700
  255.             Underline       =   0   'False
  256.             Italic          =   0   'False
  257.             Strikethrough   =   0   'False
  258.          EndProperty
  259.          ForeColor       =   &H00FFFFFF&
  260.          Height          =   240
  261.          Index           =   1
  262.          Left            =   90
  263.          TabIndex        =   31
  264.          Top             =   765
  265.          Width           =   510
  266.       End
  267.       Begin VB.Label lbRGB 
  268.          Alignment       =   2  'Center
  269.          BackColor       =   &H00FF0000&
  270.          Caption         =   "B"
  271.          BeginProperty Font 
  272.             Name            =   "MS Sans Serif"
  273.             Size            =   8.25
  274.             Charset         =   204
  275.             Weight          =   700
  276.             Underline       =   0   'False
  277.             Italic          =   0   'False
  278.             Strikethrough   =   0   'False
  279.          EndProperty
  280.          ForeColor       =   &H00FFFFFF&
  281.          Height          =   240
  282.          Index           =   2
  283.          Left            =   90
  284.          TabIndex        =   30
  285.          Top             =   1215
  286.          Width           =   510
  287.       End
  288.    End
  289.    Begin VB.CommandButton btPalette 
  290.       Caption         =   "Pale&tte >>>"
  291.       Height          =   375
  292.       Left            =   2565
  293.       TabIndex        =   25
  294.       Top             =   3600
  295.       Width           =   1995
  296.    End
  297.    Begin VB.CommandButton btExit 
  298.       Caption         =   "E&xit"
  299.       Height          =   375
  300.       Left            =   2565
  301.       TabIndex        =   24
  302.       Top             =   4005
  303.       Width           =   1995
  304.    End
  305.    Begin VB.CommandButton btDialog 
  306.       Caption         =   "Color &dialog..."
  307.       Height          =   375
  308.       Left            =   45
  309.       TabIndex        =   23
  310.       Top             =   4005
  311.       Width           =   2175
  312.    End
  313.    Begin VB.PictureBox pcMain 
  314.       AutoRedraw      =   -1  'True
  315.       Height          =   3900
  316.       Left            =   4635
  317.       MouseIcon       =   "frmColorPicker.frx":08CA
  318.       MousePointer    =   99  'Custom
  319.       ScaleHeight     =   256
  320.       ScaleMode       =   3  'Pixel
  321.       ScaleWidth      =   256
  322.       TabIndex        =   22
  323.       ToolTipText     =   "Shift + click to make a gradient"
  324.       Top             =   45
  325.       Width           =   3900
  326.    End
  327.    Begin VB.PictureBox pcVertical 
  328.       Height          =   3900
  329.       Left            =   8640
  330.       MouseIcon       =   "frmColorPicker.frx":0BD4
  331.       MousePointer    =   99  'Custom
  332.       Picture         =   "frmColorPicker.frx":0EDE
  333.       ScaleHeight     =   256
  334.       ScaleMode       =   3  'Pixel
  335.       ScaleWidth      =   18
  336.       TabIndex        =   21
  337.       ToolTipText     =   "Shift + click to make a gradient"
  338.       Top             =   45
  339.       Width           =   330
  340.    End
  341.    Begin VB.CommandButton btPick 
  342.       Caption         =   "&Pick from screen"
  343.       Height          =   375
  344.       Left            =   45
  345.       TabIndex        =   9
  346.       Top             =   3600
  347.       Width           =   2175
  348.    End
  349.    Begin VB.PictureBox lbColor 
  350.       AutoRedraw      =   -1  'True
  351.       BackColor       =   &H00000000&
  352.       ClipControls    =   0   'False
  353.       Height          =   645
  354.       Left            =   585
  355.       MouseIcon       =   "frmColorPicker.frx":4B22
  356.       MousePointer    =   99  'Custom
  357.       ScaleHeight     =   39
  358.       ScaleMode       =   3  'Pixel
  359.       ScaleWidth      =   256
  360.       TabIndex        =   37
  361.       Top             =   45
  362.       Width           =   3900
  363.       Begin VB.PictureBox pcSmall 
  364.          Appearance      =   0  'Flat
  365.          BackColor       =   &H00000000&
  366.          ForeColor       =   &H80000008&
  367.          Height          =   120
  368.          Index           =   3
  369.          Left            =   3645
  370.          ScaleHeight     =   90
  371.          ScaleWidth      =   90
  372.          TabIndex        =   42
  373.          ToolTipText     =   "Black"
  374.          Top             =   405
  375.          Width           =   120
  376.       End
  377.       Begin VB.PictureBox pcSmall 
  378.          Appearance      =   0  'Flat
  379.          BackColor       =   &H00FFFFFF&
  380.          ForeColor       =   &H80000008&
  381.          Height          =   120
  382.          Index           =   2
  383.          Left            =   3645
  384.          ScaleHeight     =   90
  385.          ScaleWidth      =   90
  386.          TabIndex        =   41
  387.          ToolTipText     =   "White"
  388.          Top             =   0
  389.          Width           =   120
  390.       End
  391.       Begin VB.PictureBox pcSmall 
  392.          Appearance      =   0  'Flat
  393.          BackColor       =   &H80000005&
  394.          ForeColor       =   &H80000008&
  395.          Height          =   120
  396.          Index           =   1
  397.          Left            =   0
  398.          ScaleHeight     =   90
  399.          ScaleWidth      =   90
  400.          TabIndex        =   40
  401.          ToolTipText     =   "Invert color"
  402.          Top             =   360
  403.          Width           =   120
  404.       End
  405.       Begin VB.PictureBox pcSmall 
  406.          Appearance      =   0  'Flat
  407.          BackColor       =   &H80000005&
  408.          ForeColor       =   &H80000008&
  409.          Height          =   120
  410.          Index           =   0
  411.          Left            =   0
  412.          ScaleHeight     =   90
  413.          ScaleWidth      =   90
  414.          TabIndex        =   39
  415.          ToolTipText     =   "Current color"
  416.          Top             =   0
  417.          Width           =   120
  418.       End
  419.    End
  420.    Begin VB.Label lbSlot 
  421.       Alignment       =   2  'Center
  422.       Appearance      =   0  'Flat
  423.       BackColor       =   &H80000005&
  424.       BorderStyle     =   1  'Fixed Single
  425.       Caption         =   "1"
  426.       ForeColor       =   &H80000008&
  427.       Height          =   285
  428.       Index           =   10
  429.       Left            =   4185
  430.       MouseIcon       =   "frmColorPicker.frx":4E2C
  431.       MousePointer    =   99  'Custom
  432.       TabIndex        =   38
  433.       Top             =   810
  434.       Width           =   300
  435.    End
  436.    Begin VB.Label lbSlot 
  437.       Alignment       =   2  'Center
  438.       Appearance      =   0  'Flat
  439.       BackColor       =   &H80000005&
  440.       BorderStyle     =   1  'Fixed Single
  441.       Caption         =   "1"
  442.       ForeColor       =   &H80000008&
  443.       Height          =   285
  444.       Index           =   9
  445.       Left            =   3840
  446.       MouseIcon       =   "frmColorPicker.frx":5136
  447.       MousePointer    =   99  'Custom
  448.       TabIndex        =   20
  449.       Top             =   810
  450.       Width           =   300
  451.    End
  452.    Begin VB.Label lbSlot 
  453.       Alignment       =   2  'Center
  454.       Appearance      =   0  'Flat
  455.       BackColor       =   &H80000005&
  456.       BorderStyle     =   1  'Fixed Single
  457.       Caption         =   "1"
  458.       ForeColor       =   &H80000008&
  459.       Height          =   285
  460.       Index           =   8
  461.       Left            =   3480
  462.       MouseIcon       =   "frmColorPicker.frx":5440
  463.       MousePointer    =   99  'Custom
  464.       TabIndex        =   19
  465.       Top             =   810
  466.       Width           =   300
  467.    End
  468.    Begin VB.Label lbSlot 
  469.       Alignment       =   2  'Center
  470.       Appearance      =   0  'Flat
  471.       BackColor       =   &H80000005&
  472.       BorderStyle     =   1  'Fixed Single
  473.       Caption         =   "1"
  474.       ForeColor       =   &H80000008&
  475.       Height          =   285
  476.       Index           =   7
  477.       Left            =   3120
  478.       MouseIcon       =   "frmColorPicker.frx":574A
  479.       MousePointer    =   99  'Custom
  480.       TabIndex        =   18
  481.       Top             =   810
  482.       Width           =   300
  483.    End
  484.    Begin VB.Label lbSlot 
  485.       Alignment       =   2  'Center
  486.       Appearance      =   0  'Flat
  487.       BackColor       =   &H80000005&
  488.       BorderStyle     =   1  'Fixed Single
  489.       Caption         =   "1"
  490.       ForeColor       =   &H80000008&
  491.       Height          =   285
  492.       Index           =   6
  493.       Left            =   2760
  494.       MouseIcon       =   "frmColorPicker.frx":5A54
  495.       MousePointer    =   99  'Custom
  496.       TabIndex        =   17
  497.       Top             =   810
  498.       Width           =   300
  499.    End
  500.    Begin VB.Label lbSlot 
  501.       Alignment       =   2  'Center
  502.       Appearance      =   0  'Flat
  503.       BackColor       =   &H80000005&
  504.       BorderStyle     =   1  'Fixed Single
  505.       Caption         =   "1"
  506.       ForeColor       =   &H80000008&
  507.       Height          =   285
  508.       Index           =   5
  509.       Left            =   2400
  510.       MouseIcon       =   "frmColorPicker.frx":5D5E
  511.       MousePointer    =   99  'Custom
  512.       TabIndex        =   16
  513.       Top             =   810
  514.       Width           =   300
  515.    End
  516.    Begin VB.Label lbSlot 
  517.       Alignment       =   2  'Center
  518.       Appearance      =   0  'Flat
  519.       BackColor       =   &H80000005&
  520.       BorderStyle     =   1  'Fixed Single
  521.       Caption         =   "1"
  522.       ForeColor       =   &H80000008&
  523.       Height          =   285
  524.       Index           =   4
  525.       Left            =   2040
  526.       MouseIcon       =   "frmColorPicker.frx":6068
  527.       MousePointer    =   99  'Custom
  528.       TabIndex        =   15
  529.       Top             =   810
  530.       Width           =   300
  531.    End
  532.    Begin VB.Label lbSlot 
  533.       Alignment       =   2  'Center
  534.       Appearance      =   0  'Flat
  535.       BackColor       =   &H80000005&
  536.       BorderStyle     =   1  'Fixed Single
  537.       Caption         =   "1"
  538.       ForeColor       =   &H80000008&
  539.       Height          =   285
  540.       Index           =   3
  541.       Left            =   1680
  542.       MouseIcon       =   "frmColorPicker.frx":6372
  543.       MousePointer    =   99  'Custom
  544.       TabIndex        =   14
  545.       Top             =   810
  546.       Width           =   300
  547.    End
  548.    Begin VB.Label lbSlot 
  549.       Alignment       =   2  'Center
  550.       Appearance      =   0  'Flat
  551.       BackColor       =   &H80000005&
  552.       BorderStyle     =   1  'Fixed Single
  553.       Caption         =   "1"
  554.       ForeColor       =   &H80000008&
  555.       Height          =   285
  556.       Index           =   2
  557.       Left            =   1320
  558.       MouseIcon       =   "frmColorPicker.frx":667C
  559.       MousePointer    =   99  'Custom
  560.       TabIndex        =   13
  561.       Top             =   810
  562.       Width           =   300
  563.    End
  564.    Begin VB.Label lbSlot 
  565.       Alignment       =   2  'Center
  566.       Appearance      =   0  'Flat
  567.       BackColor       =   &H80000005&
  568.       BorderStyle     =   1  'Fixed Single
  569.       Caption         =   "1"
  570.       ForeColor       =   &H80000008&
  571.       Height          =   285
  572.       Index           =   1
  573.       Left            =   960
  574.       MouseIcon       =   "frmColorPicker.frx":6986
  575.       MousePointer    =   99  'Custom
  576.       TabIndex        =   12
  577.       Top             =   810
  578.       Width           =   300
  579.    End
  580.    Begin VB.Label lbSlot 
  581.       Alignment       =   2  'Center
  582.       Appearance      =   0  'Flat
  583.       BackColor       =   &H80000005&
  584.       BorderStyle     =   1  'Fixed Single
  585.       Caption         =   "1"
  586.       ForeColor       =   &H80000008&
  587.       Height          =   285
  588.       Index           =   0
  589.       Left            =   600
  590.       MouseIcon       =   "frmColorPicker.frx":6C90
  591.       MousePointer    =   99  'Custom
  592.       TabIndex        =   11
  593.       ToolTipText     =   "Right-click to remember, left-click to retrieve"
  594.       Top             =   810
  595.       Width           =   300
  596.    End
  597.    Begin VB.Label Label1 
  598.       Caption         =   "Slots:"
  599.       Height          =   285
  600.       Left            =   60
  601.       TabIndex        =   10
  602.       Top             =   825
  603.       Width           =   465
  604.    End
  605.    Begin VB.Label lbGetColor 
  606.       Caption         =   "Color:"
  607.       Height          =   330
  608.       Left            =   45
  609.       TabIndex        =   0
  610.       Top             =   90
  611.       Width           =   510
  612.    End
  613. Attribute VB_Name = "frmColorPicker"
  614. Attribute VB_GlobalNameSpace = False
  615. Attribute VB_Creatable = False
  616. Attribute VB_PredeclaredId = True
  617. Attribute VB_Exposed = False
  618. '***********************************************************************
  619. '*               BF Color Picker from BugFull Software                 *
  620. '*           written by Chavdar Jordanov (chavo@beer.com)              *
  621. '*     You may freely use and modify this code as long as you keep     *
  622. '*                       this title intact.                            *
  623. '*              Hope its gonna be useful for you!                      *
  624. '***********************************************************************
  625. '----- Note from the author: I deliberately did not use any API calls or C++ routines.
  626. '-     Some of this code may work more efficiently with API or a C++ dll, but I am trying
  627. '-     to show what can be done in pure Visual Basic. Good luck!
  628. '----------------------------------------------------------------------------------
  629. Option Explicit
  630. Dim Col As Long                     'The main color
  631. Dim bMouseOverPalette As Boolean    'Mouse is over the gradient palette
  632. Dim OldX As Long
  633. Const BigForm = 9200
  634. Const SmallForm = 4700
  635. '----- copies the color value to the Clipboard --------
  636. Private Sub btCopy_Click(Index As Integer)
  637.     Dim S As String
  638.     S = txCol(Index).Text
  639.     Clipboard.Clear
  640.     Clipboard.SetText S
  641. End Sub
  642. '------ shows the windows color dialog ---------------
  643. Private Sub btDialog_Click()
  644.     On Error GoTo 100
  645.     CDL.CancelError = True
  646.     CDL.Flags = cdlCCRGBInit
  647.     CDL.Color = lbColor.BackColor
  648.     CDL.ShowColor
  649.     Col = CDL.Color
  650.     'ShowColors (Col)
  651.     Exit Sub
  652.     Resume 10
  653. End Sub
  654. Private Sub btExit_Click()
  655.     Unload Me
  656.     End
  657. End Sub
  658. '----------- unfolds or folds the form to show or hide the palette window -----
  659. Private Sub btPalette_Click()
  660.     If Me.Width = BigForm Then
  661.         Me.Width = SmallForm
  662.         btPalette.Caption = "&Palette >>>"
  663.     Else
  664.         Me.Width = BigForm
  665.         btPalette.Caption = "&Palette <<<"
  666.         If opPal(0) Then ShowGradientPalette Col
  667.     End If
  668. End Sub
  669. '----------- captures the screen to frmScreen ------------
  670. Private Sub btPick_Click()
  671.     PrepareScreen
  672.     btPick.Enabled = False
  673. End Sub
  674. '----------- shows a color from the IE color table ---------
  675. Private Sub cbWeb_Click()
  676.     If cbWeb.ListIndex > 0 Then
  677.         Col = cbWeb.ItemData(cbWeb.ListIndex)
  678.         ShowColors Col
  679.     End If
  680. End Sub
  681. Private Sub chHue_Click()
  682.     ShowGradientPalette Col
  683. End Sub
  684. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  685.     If KeyCode = vbKeyF1 Then
  686.         MsgBox "BF Color Picker (Freeware)" + vbCrLf + "BugFull Software 2001" + vbCrLf + "Written by Chavdar Yordanov" + vbCrLf + "E-mail: chavo@beer.com", vbInformation, "About BF Color Picker"
  687.     End If
  688. End Sub
  689. Private Sub Form_Load()
  690.     Col = RGB(255, 255, 255)
  691.     ArrangeSmall             'arranges the small color slots within the lbColor
  692.     Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2 'center the form
  693.     GetSlots                 'retrieves saved color values from registry
  694.     GetWebColors Me.cbWeb    'load color values and names into the combo box
  695.     iColorDepth = clr24Bit   'sets the default color depth
  696.     opPal(1).Value = True
  697.     Me.Width = SmallForm
  698.     Me.Show
  699.     ShowColors Col
  700. End Sub
  701. Private Sub Form_Unload(Cancel As Integer)
  702.     End
  703. End Sub
  704. Private Sub lbCol_Click(Index As Integer)
  705.     btCopy_Click (Index)
  706. End Sub
  707. '------------- the main sub where it all takes place --------
  708. Sub ShowColors(ByVal iCol As Long) 'Calculates the R<G<B values and writes them to the text boxes
  709.     Dim R, G, B, i
  710.     Dim bTmp(1 To 3) As Byte
  711.     On Error Resume Next
  712.     If iCol < 0 Then Exit Sub
  713.     iCol = CalcColorDepth(iCol)
  714.     lbColor.BackColor = iCol
  715.     txCol(0).Text = CStr(iCol)
  716.     'Split the long value into separate bytes
  717.     SplitIntoBytes iCol, 3, bTmp, False
  718.     'Assign the byte values to R,G,B variables just for convenience
  719.     B = bTmp(3)
  720.     G = bTmp(2)
  721.     R = bTmp(1)
  722.     lbRGB(0).BackColor = RGB(R, 0, 0)
  723.     lbRGB(1).BackColor = RGB(0, G, 0)
  724.     lbRGB(2).BackColor = RGB(0, 0, B)
  725.     scColor(0).Value = R
  726.     scColor(1).Value = G
  727.     scColor(2).Value = B
  728.     txCol(1) = "#" + Format(Hex(R), "00") + Format(Hex(G), "00") + Format(Hex(B), "00")
  729.     txCol(2) = Format(R) + "," + Format(G) + "," + Format(B)
  730.         
  731.     pcSmall(0).BackColor = Col
  732.     pcSmall(1).BackColor = Invert(Col)
  733.     For i = 1 To cbWeb.ListCount - 1
  734.         If cbWeb.ItemData(i) = Col Then
  735.             cbWeb.ListIndex = i
  736.             If opPal(2).Value Then ShowIEPalette Col
  737.             Exit Sub
  738.         End If
  739.     Next i
  740.     If opPal(1).Value Then ShowSafeSwatches Col
  741.     cbWeb.ListIndex = 0
  742. End Sub
  743. Private Sub lbColor_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  744.     Col = lbColor.Point(x, y)
  745.     ShowColors Col
  746.     If Me.Width = BigForm And opPal(0).Value Then ShowGradientPalette Col
  747. End Sub
  748. '--------- sets or retrieves a color from the color slots ----------
  749. Private Sub lbSlot_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
  750.     If Button = vbLeftButton Then
  751.         If Shift = 1 Then
  752.             ShowGradient Col, lbSlot(Index).BackColor
  753.         Else
  754.             Col = lbSlot(Index).BackColor
  755.             ShowColors Col
  756.         End If
  757.         If opPal(0) Then ShowGradientPalette Col
  758.     Else
  759.         lbSlot(Index).BackColor = lbColor.BackColor
  760.         SaveSlots
  761.     End If
  762. End Sub
  763. Private Sub opModify_Click(Index As Integer)
  764.     iColorDepth = Choose(Index + 1, clr24Bit, clr16Bit, clrWebSafe)
  765.     If Me.Width = BigForm And opPal(0).Value Then ShowGradientPalette Col
  766. End Sub
  767. '---------- shows one of the 3 available palettes -------------
  768. Private Sub opPal_Click(Index As Integer)
  769.     Select Case Index
  770.     Case 0 'Gradient palette
  771.         ShowGradientPalette Col
  772.     Case 1 'Swatches 216 col
  773.         ShowSafeSwatches
  774.     Case 2 'swatches IE 4+
  775.         ShowIEPalette
  776.     End Select
  777. '    chHue.Enabled = Index = 0
  778. End Sub
  779. Private Sub pcMain_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  780.     Dim lCol As Long
  781.     bMouseOverPalette = True
  782.     lCol = pcMain.Point(x, y)
  783.     If Shift = 1 Then
  784.         ShowGradient Col, lCol
  785.     Else
  786.         ShowColors lCol
  787.     End If
  788. End Sub
  789. Private Sub pcMain_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  790.     bMouseOverPalette = False
  791. End Sub
  792. Private Sub pcSmall_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
  793.     If Shift = 1 Then
  794.         ShowGradient Col, pcSmall(Index).BackColor
  795.     Else
  796.         Col = pcSmall(Index).BackColor
  797.         ShowColors Col
  798.     End If
  799. End Sub
  800. Private Sub scColor_Change(Index As Integer)
  801.     Col = RGB(scColor(0).Value, scColor(1).Value, scColor(2).Value)
  802.     ShowColors Col
  803. End Sub
  804. Private Sub txCol_GotFocus(Index As Integer)
  805.     SelectAll Index
  806. End Sub
  807. '---------- validates the input from the text boxes -----------
  808. Private Sub txCol_KeyPress(Index As Integer, KeyAscii As Integer)
  809.     If KeyAscii = 13 Then
  810.         SetColors Index
  811.         SelectAll Index
  812.         Exit Sub
  813.     End If
  814.     Dim sAllowed As String
  815.     If KeyAscii > 31 Then
  816.         Select Case Index
  817.             Case 0
  818.                 sAllowed = "0123456789"
  819.             Case 1
  820.                 sAllowed = "#0123456789abcdefABCDEF"
  821.             Case 2
  822.                 sAllowed = "0123456789,"
  823.         End Select
  824.         If InStr(sAllowed, Chr(KeyAscii)) = 0 Then KeyAscii = 0
  825.     End If
  826. End Sub
  827. '--------- converts typed values to color --------------
  828. Sub SetColors(iType As Integer)
  829.     Dim sCol As String, N As Integer, i
  830.     sCol = Condense(txCol(iType).Text)
  831.     Col = 0
  832.     On Error Resume Next
  833.     Select Case iType
  834.         Case 0 'Long
  835.             Col = Val(sCol)
  836.         Case 1 'Hex
  837.             Col = HexToLong(sCol)
  838.         Case 2 'RGB
  839.             Col = RgbToLong(sCol)
  840.     End Select
  841.     ShowColors Col
  842. End Sub
  843. Function Condense(S As String) As String  'Removes all spaces from a string
  844.     Dim i, C, Z
  845.     Z = ""
  846.     For i = 1 To Len(S)
  847.         C = Mid(S, i, 1)
  848.         If C <> " " Then Z = Z + C
  849.     Next i
  850.     Condense = Z
  851. End Function
  852. Sub SelectAll(Index As Integer)
  853.     With txCol(Index)
  854.         .SelStart = 0
  855.         .SelLength = Len(.Text)
  856.     End With
  857. End Sub
  858. '---------- retrieves the color values for the slots from registry ----------
  859. Sub GetSlots()
  860.     Dim i
  861.     For i = 0 To lbSlot.Count - 1
  862.         lbSlot(i).Caption = " "
  863.         lbSlot(i).ToolTipText = "Right-click to remember, left-click to retrieve"
  864.         lbSlot(i).BackColor = GetSetting("BFColorPicker", "Slots", "Color" + CStr(i), vbWhite)
  865.     Next i
  866. End Sub
  867. '---------- saves the color values to the registry --------------
  868. Sub SaveSlots()
  869.     Dim i
  870.     For i = 0 To lbSlot.Count - 1
  871.         SaveSetting "BFColorPicker", "Slots", "Color" + CStr(i), CStr(lbSlot(i).BackColor)
  872.     Next i
  873. End Sub
  874. '=========== SCREEN CAPTURE FUNCTIONS =============
  875. Private Sub PrepareScreen()
  876.     Screen.MousePointer = 11
  877.     If frmScreen.Visible = True Then
  878.         Unload frmScreen
  879.         Exit Sub
  880.     Else
  881.         'prepare frmScreen and capture the screen into picture1.
  882.         frmScreen.Move 0, 0, Screen.Width, Screen.Height
  883.         frmScreen.Picture1.Move 0, 0, frmScreen.Width, frmScreen.Height
  884.         frmScreen.MousePointer = 99
  885.         Set frmScreen.MouseIcon = lbColor.MouseIcon
  886.         Set frmScreen.Picture1.Picture = CaptureScreen()
  887.         frmScreen.Visible = True
  888.     End If
  889.     Screen.MousePointer = 0
  890. End Sub
  891. '============= COLOR PALETTE FUNCTIONS ================
  892. Private Sub pcMain_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  893.     Dim lCol As Long
  894.     If bMouseOverPalette Then
  895.         lCol = pcMain.Point(x, y)
  896.         ShowColors lCol
  897.     End If
  898. End Sub
  899. '----------- picks a color from the vertical palette on the right --------
  900. Private Sub pcVertical_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  901.     Dim lMaxColor As Long
  902.     lMaxColor = pcVertical.Point(x, y)
  903.     If Shift = 0 Then ShowColors lMaxColor Else ShowGradient Col, lMaxColor
  904.     If opPal(0) Then ShowGradientPalette lMaxColor
  905.     DoEvents
  906. End Sub
  907. '-------- shows the gradient palette (faster than the sub from the previous version which used PSET) -------
  908. '-        takes about 0.5 seconds on my Athlon 600 machine
  909. '-        Creates a bitmap file on the disk and then loads it into the picture box
  910. '------------------------------------------------------------------
  911. Public Sub ShowGradientPalette(ByVal lMaxColor As Long)
  912.     Dim i As Long, j As Long              'Counters
  913.     Dim R As Long, G As Long, B As Long        'Color values as bytes
  914.     Dim k As Single                             'needed for the calculations
  915.     Dim KF As Single                            'needed for the calculations
  916.     Dim cPos As Long                            'Current position within the bitmap array
  917.     Dim sFileName As String                     'Temporary name for the bitmap file
  918.     Dim bBitmap(1 To 256 ^ 2 * 3 + 54) As Byte  'The array containing all the bitmap information to be saved to disk
  919.     Dim bColorBytes(1 To 3) As Byte        'Holder for the RGB values
  920.     Dim NewCol As Long
  921.     Dim T
  922.     Const bmpOffset = 54            'the header size for the bitmap disk file. Must skip it when loading color values into the bitmap array
  923.     If lMaxColor < 0 Then Exit Sub  'Happens when user clicks on the picturebox borders
  924.     Screen.MousePointer = 11
  925.     SplitIntoBytes lMaxColor, 3, bColorBytes(), False
  926.     R = bColorBytes(1)
  927.     G = bColorBytes(2)
  928.     B = bColorBytes(3)
  929.     cPos = bmpOffset                'start writing color values after the file header
  930.     T = Timer
  931.     For i = 0 To 255
  932.         KF = (i / 65025)
  933.         For j = 255 To 0 Step -1
  934.             k = (255 - j) * KF
  935.             bColorBytes(1) = GetColorByte(k * B + j) 'CalcByte(B, i, j)       '(k * B + j)
  936.             bColorBytes(2) = GetColorByte(k * G + j)
  937.             bColorBytes(3) = GetColorByte(k * R + j)
  938.             MergeBytes bBitmap(), bColorBytes(), cPos      'write the 3 byte color value to the bitmap array
  939.         Next j
  940.     Next i
  941.     sFileName = "c:\cppal.bmp"                        'Assigns a temporary file for the bitmap palette
  942.     Create24bitBitmap 256, 256, bBitmap(), sFileName  'creates a bitmap containg the palette on the harddisk
  943.     Set pcMain.Picture = LoadPicture(sFileName)    'and loads it into pcMain
  944.     Kill sFileName                                    'Delete the temporary file
  945.     Screen.MousePointer = 0
  946.     Debug.Print Int((Timer - T) * 1000)
  947. End Sub
  948. '----------- Shows a gradient between lMinCol and lMaxCol in lbColor ----------
  949. Sub ShowGradient(ByVal lMinCol, ByVal lMaxCol)
  950.     Dim i As Long, H, W
  951.     Dim r1 As Long, r2 As Long, g1 As Long
  952.     Dim g2 As Long, b1 As Long, b2 As Long
  953.     Dim bBytes() As Byte
  954.     Dim NewR As Long, NewB As Long, NewG As Long
  955.     Dim NewCol As Long
  956.     Dim Perc As Byte
  957.     If lMinCol < 0 Or lMaxCol < 0 Then Exit Sub
  958.     Screen.MousePointer = 11
  959.     SplitIntoBytes lMaxCol, 3, bBytes()
  960.     b1 = bBytes(3)
  961.     g1 = bBytes(2)
  962.     r1 = bBytes(1)
  963.     SplitIntoBytes lMinCol, 3, bBytes()
  964.     b2 = bBytes(3)
  965.     g2 = bBytes(2)
  966.     r2 = bBytes(1)
  967.     lbColor.Cls
  968.     lbColor.DrawMode = 13
  969.     ShowColors lMaxCol
  970.     H = lbColor.ScaleHeight
  971.     W = lbColor.ScaleWidth
  972.     lbColor.DrawMode = 13
  973.     For i = 0 To 255
  974.         NewR = i / 255 * r1 + (255 - i) / 255 * r2
  975.         NewG = i / 255 * g1 + (255 - i) / 255 * g2
  976.         NewB = i / 255 * b1 + (255 - i) / 255 * b2
  977.         NewCol = CalcColorDepth(RGB(NewR, NewG, NewB))
  978.         lbColor.Line (i, 0)-(i, H), NewCol
  979.     Next i
  980.     lbColor.DrawMode = 6
  981.     lbColor.Line (0, H * 2 / 3)-(W, H * 2 / 3)
  982.     Perc = 0
  983.     For i = 0 To W Step W / 10
  984.         lbColor.Line (i - 1, H * 2 / 3 - 5)-(i - 1, H * 2 / 3)
  985.         lbColor.CurrentX = i - 6
  986.         lbColor.CurrentY = H * 2 / 3 + 1
  987.         lbColor.FontSize = 7
  988.         lbColor.FontName = "Arial"
  989.         If Perc > 0 Then lbColor.Print Perc
  990.         Perc = Perc + 1
  991.     Next i
  992.     lbColor.DrawMode = 13
  993.     Screen.MousePointer = 0
  994. End Sub
  995. '-------- arranges the small color slots in the right-top corner of the lbColor -----
  996. Sub ArrangeSmall()
  997.     Dim i
  998.     For i = 1 To 4
  999.         pcSmall(4 - i).Move lbColor.ScaleWidth - pcSmall(4 - i).Width * i, -1
  1000.     Next i
  1001. End Sub
  1002. '----------- shows the Internet Explorer color palette -------------
  1003. Private Sub ShowIEPalette(Optional ByVal ShowCol = -1)
  1004.     Dim HH, WW, i, j
  1005.     Dim Cnt As Integer
  1006.     Dim iCol As Long
  1007.     Dim bCol(140)
  1008.     For i = 1 To cbWeb.ListCount - 1
  1009.         bCol(i) = cbWeb.ItemData(i)
  1010.     Next i
  1011.     'SortArray bCol()
  1012.     With pcMain
  1013.         .Cls
  1014.         WW = .ScaleWidth / 12
  1015.         HH = .ScaleHeight / 12
  1016.         Cnt = 0
  1017.         For i = 0 To 11
  1018.             For j = 0 To 11
  1019.                 Cnt = Cnt + 1
  1020.                 If Cnt > 140 Then Exit For
  1021.                 pcMain.Line (j * WW, i * HH)-((j + 1) * WW, (i + 1) * HH), bCol(Cnt), BF
  1022.                 If ShowCol = bCol(Cnt) Then iCol = vbWhite Else iCol = vbBlack
  1023.                 pcMain.Line (j * WW, i * HH)-((j + 1) * WW, (i + 1) * HH), iCol, B
  1024.             Next j
  1025.         Next i
  1026.     End With
  1027. End Sub
  1028. '---------------- shows 216 color palette ----------------
  1029. Private Sub ShowSafeSwatches(Optional ByVal ShowCol = -1)
  1030.     Dim HH, WW, i, j
  1031.     Dim Cnt As Integer
  1032.     Dim iCol As Long
  1033.     With pcMain
  1034.         .Cls
  1035.         WW = .ScaleWidth / 16
  1036.         HH = .ScaleHeight / 14
  1037.         Cnt = 0
  1038.         For i = 0 To 15
  1039.             For j = 0 To 13
  1040.                 Cnt = Cnt + 1
  1041.                 If Cnt > 224 Then Exit Sub
  1042.                 pcMain.Line (i * WW, j * HH)-((i + 1) * WW, (j + 1) * HH), SafeCol(Cnt), BF
  1043.                 If ShowCol = SafeCol(Cnt) Then iCol = vbWhite Else iCol = vbBlack
  1044.                 pcMain.Line (i * WW, j * HH)-((i + 1) * WW, (j + 1) * HH), iCol, B
  1045.             Next j
  1046.         Next i
  1047.     End With
  1048. End Sub
  1049.